package com.zhang.order.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.member.entity.MemberUser;
import com.zhang.member.service.IMemberUserService;
import com.zhang.order.entity.AppraiseReply;
import com.zhang.order.mapper.AppraiseReplyMapper;
import com.zhang.order.service.IAppraiseReplyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 商品评价的回复 服务实现类
 * </p>
 *
 * @author 创世神
 * @since 2024-04-20
 */
@Service
public class AppraiseReplyServiceImpl extends ServiceImpl<AppraiseReplyMapper, AppraiseReply> implements IAppraiseReplyService {
    @Autowired
    private IMemberUserService memberUserService;

    @Override
    public void addAppraiseReply(AppraiseReply appraiseReply) {
        appraiseReply.setUserId(StpUtil.getLoginIdAsLong());
        MemberUser byId = memberUserService.getById(StpUtil.getLoginIdAsLong());
        appraiseReply.setUserName(byId.getUserNickname());
        appraiseReply.setAvatar(byId.getAvatar());
        save(appraiseReply);
    }

    @Override
    public Page<AppraiseReply> AppraiseReplyList(Map<String,Long> map) {
        Long pageNum = map.get("pageNum");
        Long pageSize = map.get("pageSize");
        Long appraiseId = map.get("appraiseId");
        LambdaQueryWrapper<AppraiseReply> wrapper = new LambdaQueryWrapper<>();
        if (appraiseId!=null){
            wrapper.eq(AppraiseReply::getAppraiseId,appraiseId);
        }
        return page(new Page<>(pageNum, pageSize),wrapper);
    }
}
